gdk: Add a copy of some deprecated pango api
authorMatthias Clasen <mclasen@redhat.com>
Thu, 31 Jan 2019 19:03:49 +0000 (14:03 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 4 Feb 2019 23:28:31 +0000 (18:28 -0500)
We use pango_find_base_dir() in a few places, and
this api has been deprecated.

gdk/gdk-private.h
gdk/gdk.c
gdk/gdkinternals.h

index 0c83002bfc4a35dbbdb7975e7a34183e56de1ddb..551ecac9aa334a88b53a3a2513205cce752d943d 100644 (file)
@@ -36,4 +36,8 @@ gboolean gdk_should_use_portal (void);
 
 const gchar *   gdk_get_startup_notification_id (void);
 
+PangoDirection gdk_unichar_direction (gunichar    ch);
+PangoDirection gdk_find_base_dir     (const char *text,
+                                      int         len);
+
 #endif /* __GDK__PRIVATE_H__ */
index d623afabf9eaab10251275c3061c3eef68188e3d..6954ef772e2b391194ce1996bb116356578300fa 100644 (file)
--- a/gdk/gdk.c
+++ b/gdk/gdk.c
@@ -40,6 +40,8 @@
 #include <string.h>
 #include <stdlib.h>
 
+#include <fribidi.h>
+
 
 /**
  * SECTION:general
@@ -343,3 +345,45 @@ gdk_should_use_portal (void)
  * management for you.
  */
 
+PangoDirection
+gdk_unichar_direction (gunichar ch)
+{
+  FriBidiCharType fribidi_ch_type;
+
+  G_STATIC_ASSERT (sizeof (FriBidiChar) == sizeof (gunichar));
+
+  fribidi_ch_type = fribidi_get_bidi_type (ch);
+
+  if (!FRIBIDI_IS_STRONG (fribidi_ch_type))
+    return PANGO_DIRECTION_NEUTRAL;
+  else if (FRIBIDI_IS_RTL (fribidi_ch_type))
+    return PANGO_DIRECTION_RTL;
+  else
+    return PANGO_DIRECTION_LTR;
+}
+
+PangoDirection
+gdk_find_base_dir (const gchar *text,
+                   gint         length)
+{
+  PangoDirection dir = PANGO_DIRECTION_NEUTRAL;
+  const gchar *p;
+
+  g_return_val_if_fail (text != NULL || length == 0, PANGO_DIRECTION_NEUTRAL);
+
+  p = text;
+  while ((length < 0 || p < text + length) && *p)
+    {
+      gunichar wc = g_utf8_get_char (p);
+
+      dir = gdk_unichar_direction (wc);
+
+      if (dir != PANGO_DIRECTION_NEUTRAL)
+        break;
+
+      p = g_utf8_next_char (p);
+    }
+
+  return dir;
+}
+
index f64f38dd4b559fe649ef20cd8df91e9ecc07b812..a8c4bb617685568ff607f7551b438db442492f42 100644 (file)
@@ -351,7 +351,6 @@ void gdk_synthesize_surface_state (GdkSurface     *surface,
                                    GdkSurfaceState unset_flags,
                                    GdkSurfaceState set_flags);
 
-
 G_END_DECLS
 
 #endif /* __GDK_INTERNALS_H__ */